import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner scan=new Scanner(System.in);
        while(scan.hasNext()){
            int n=scan.nextInt();
            if(n==0){
                break;
            }else{
                System.out.println(getNum(n));
            }
        }
    }
    public static int getNum(int num){
        int sum=0;
        while(num>=2){
            sum+=num/3;
            if(num==2){
                sum+=1;
                break;
            }
            num=num%3+num/3;
        }
        return sum;
    }
}
